﻿using System.Data.Entity;

namespace LifeMed.Data.Core.ContextFactory
{
    public class DbContextFactory : IDbContextFactory

    {
            private DbContext _dbContext;

            // return actual instance od DbContext if null set DefaulContext
            public DbContext Instance
            {
                get { return _dbContext ?? (_dbContext = new DefaultContext()); }
                set { _dbContext = value; }
            }

        //protected override void DisposeCore()
        //    {
        //        if (dataContext != null)
        //            dataContext.Dispose();
        //    }

        #region Implementation of IDisposable

        public void Dispose()
        {
            if (_dbContext != null)
                   _dbContext.Dispose();
        }

        #endregion
    }
}